<script setup lang="ts">
import { PieChartOutlined, DesktopOutlined, UserOutlined, TeamOutlined, FileOutlined } from '@ant-design/icons-vue'
import { useRoute, useRouter } from 'vue-router'
const currentRoute = useRoute()
const router = useRouter()
interface Route {
  parentPath?: string
  path: string
  meta?: Object
  children?: Array<{
    parentPath: string
    path: string
    meta?: Object
    children?: Array<{
      parentPath: string
      path: string
      meta?: Object
    }>
  }>
}

const routes = ref<Route[]>([
  {
    path: '/',
    meta: {
      title: '实时舆情线索管理'
    },
    children: [
      {
        parentPath: 'ssyq-list',
        path: '/ssyq/list',
        meta: {
          title: '实时舆情线索管理列表'
        },
        children: [
          {
            parentPath: 'ssyq-list',
            path: '/ssyq/list/detail',
            meta: {
              title: '实时舆情线索管理详情'
            }
          }
        ]
      },
      {
        parentPath: '/qyyq/list',
        path: '/qyyq/list',
        meta: {
          title: '区域舆情线索管理列表'
        },
        children: [
          {
            parentPath: '/qyyq/list',
            path: '/qyyq/list/detail',
            meta: {
              title: '区域舆情线索管理详情'
            }
          }
        ]
      }
    ]
  }
])

const collapsed = ref<boolean>(false)
const selectedKeys = ref<string[]>(['1'])

onMounted(() => {
  console.log(currentRoute.fullPath, 'currentRoute')
  switch (currentRoute.fullPath) {
    case '/ssyq/list':
      selectedKeys.value = ['1']
      break
    case '/qyyq/list':
      selectedKeys.value = ['2']
      break
    case '/zxyq/list':
      selectedKeys.value = ['3']
      break
    case '/yqxs/list':
      selectedKeys.value = ['4']
      break
    case '/znss/list':
      selectedKeys.value = ['5']
      break
    default:
      selectedKeys.value = ['1']
      break
  }
})
</script>

<template>
  <a-layout style="min-height: 100vh">
    <a-layout-sider v-model:collapsed="collapsed" collapsible>
      <div class="logo">舆情管理系统</div>
      <a-menu v-model:selectedKeys="selectedKeys" theme="dark" mode="inline">
        <a-menu-item key="1">
          <pie-chart-outlined />
          <span>
            <router-link to="/ssyq/list" @click.prevent="onMenu(1)"> 实时舆情线索管理 </router-link>
          </span>
        </a-menu-item>
        <a-menu-item key="2">
          <desktop-outlined />
          <span>
            <router-link to="/qyyq/list" @click.prevent="onMenu(2)"> 区域舆情线索管理 </router-link>
          </span>
        </a-menu-item>
        <a-menu-item key="3">
          <desktop-outlined />
          <span>
            <router-link to="/zxyq/list" @click.prevent="onMenu(3)"> 专项舆情线索管理 </router-link>
          </span>
        </a-menu-item>
        <a-menu-item key="4">
          <desktop-outlined />
          <span>
            <router-link to="/yqxs/list" @click.prevent="onMenu(4)"> 舆情线索预警管理 </router-link>
          </span>
        </a-menu-item>
        <a-menu-item key="5">
          <desktop-outlined />
          <span>
            <router-link to="/znss/list" @click.prevent="onMenu(5)"> 智能实时预警管理 </router-link>
          </span>
        </a-menu-item>
        <!-- <a-sub-menu key="sub1">
          <template #title>
            <span>
              <user-outlined />
              <span>User</span>
            </span>
          </template>
          <a-menu-item key="3">Tom</a-menu-item>
          <a-menu-item key="4">Bill</a-menu-item>
          <a-menu-item key="5">Alex</a-menu-item>
        </a-sub-menu>
        <a-sub-menu key="sub2">
          <template #title>
            <span>
              <team-outlined />
              <span>Team</span>
            </span>
          </template>
          <a-menu-item key="6">Team 1</a-menu-item>
          <a-menu-item key="8">Team 2</a-menu-item>
        </a-sub-menu>
        <a-menu-item key="9">
          <file-outlined />
          <span>File</span>
        </a-menu-item> -->
      </a-menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 0" />
      <a-layout-content style="margin: 0 16px">
        <a-breadcrumb :routes="routes">
          <template #itemRender="{ route, routes }">
            <span v-if="routes.indexOf(route) === routes.length - 1"> {{ route.meta.title }} </span>
            <template v-for="childItem in route.children" :key="childItem.path">
              <router-link v-if="currentRoute.fullPath.indexOf(childItem.path) > -1" :to="childItem.path">
                /{{ childItem.meta.title }}
              </router-link>
              <template v-for="item in childItem.children" :key="item.path">
                <router-link v-if="item.path === currentRoute.path" :to="item.path">
                  /{{ item.meta.title }}
                </router-link>
              </template>
            </template>
          </template>
        </a-breadcrumb>
        <div :style="{ padding: '24px', background: '#fff', minHeight: '360px' }">
          <router-view v-slot="{ Component }">
            <transition name="zoom-fade" mode="out-in" appear>
              <component :is="Component" />
            </transition>
          </router-view>
        </div>
      </a-layout-content>
      <a-layout-footer style="text-align: center"> Design ©2023 Created by blake </a-layout-footer>
    </a-layout>
  </a-layout>
</template>

<style lang="scss" scoped>
.logo {
  height: 32px;
  margin: 16px;
  background: rgba(255, 255, 255, 0.3);
  font-size: 22px;
  color: #fff;
}

.site-layout .site-layout-background {
  background: #fff;
}
[data-theme='dark'] .site-layout .site-layout-background {
  background: #141414;
}

:deep(.ant-layout-sider-children) {
  .ant-menu-item {
    height: 80px;
    line-height: 80px;
  }
}
</style>
